<template>
  <div class="approval">
    <el-card class="box-card" style="margin-bottom: 10px;">
      <div class="head-title2">
          <div class="title">{{$t('approval.HistoryRecord')}}</div>
          <div class="info">
            <el-button
              type="primary"
              size="small"
              @click.stop="addDescFn"
              style="background: #6083f7; border-color: #6083f7;"
            >{{$t('approvalDetail.seeDesc')}}</el-button>
          </div>
        </div>
      <div style="padding-left: 12px;">  
        <el-table :data="userAllInfoDetail" border stripe style="width: 100%;margin-top: 10px;">
          <el-table-column
            header-align="center"
            align="center"
            prop="crtTime"
            :label="$t('approval.time')"
            width="156"
          ></el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="appName"
            :label="$t('approval.ApplyChannel')"
            width="146"
          ></el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            :label="$t('collDetail.orderIds')"
            width="146"
            prop="orderId"
          ></el-table-column>
          <el-table-column
          header-align="center"
          align="center"
          prop='proName'
          :label="$t('approval.proName')"
          width='162'>
          </el-table-column>
          <el-table-column
          header-align="center"
          align="center"
          prop='appUserNameNew'
          :label="$t('approvalDetail.mobile')"
          width="146">
          </el-table-column>
          <!-- <el-table-column
          header-align="center"
          align="center"
          prop='IdNumber'
          :label="$t('approval.IdNumber')"
          width='160'>
          </el-table-column> -->
          <el-table-column
            header-align="center"
            align="center"
            prop="approvedAmt"
            :label="$t('approval.LoanAmount')"
            width="146"
          ></el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="proTerm"
            :label="$t('approval.CurrentApply')"
            width="146"
          ></el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="status"
            :label="$t('approval.LoanStatus')"
            width="146"
          >
          <template slot-scope="scope">
              <span v-if="scope.row.status === 1">{{$t('approval.audit')}}</span>
              <span v-if="scope.row.status === 2">{{$t('approval.credit')}}</span>
              <span v-if="scope.row.status === 3">{{$t('approval.repayments')}}</span>
              <span v-if="scope.row.status === 4">{{$t('approval.refused')}}</span>
              <span v-if="scope.row.status === 5">{{$t('approval.clear')}}</span>
              <span v-if="scope.row.status === 6">{{$t('approvalDetail.status4')}}</span>
              <span v-if="scope.row.status === 7">{{$t('approvalDetail.status5')}}</span>
              <span v-if="scope.row.status === 8">{{$t('approvalDetail.status6')}}</span>
              <span v-if="scope.row.status === 9">{{$t('orderQuery.status9')}}</span>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="overdueDayNew"
            :label="$t('processing.overDay')"
            width="146"
          ></el-table-column>
        </el-table>
      </div>
      <div class="pagination-container">
        <el-pagination
          @size-change="handleSizeChangeUserInfo"
          @current-change="handleCurrentChangeUserInfo"
          :current-page="userAllInfoPage.page"
          :page-sizes="[5, 10, 20, 50]"
          :page-size="userAllInfoPage.limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="userInfoTotal"
        ></el-pagination>
      </div>
    </el-card>
    <el-dialog :title="$t('approvalDetail.historyDesc')" :visible.sync="dialogDescForm">
      <el-form
        :model="descForm"
        ref="descForm"
        label-width="100px"
        style="width: 90%; padding-bottom: 10px;"
      >
        <el-form-item :label="$t('grouping.remark')">
          <el-input
            type="textarea"
            size="small"
            v-model="descForm.remark"
            :placeholder="$t('rule.toLength')"
            :maxlength="500"
            disabled=""
          ></el-input>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { userAllOrderByChannel, getApprovalRemark } from "api/trust/firstApprDetails/index";
export default {
  data() {
    return {
      listObj: {},
      userInfoTotal: null,
      userAllInfoPage: {
        limit: 5,
        page: 1,
        orderId: "",
        channel: ""
      },
      userAllInfoDetail: [],
      dialogDescForm: false,
      descForm: {
        remark: ""
      },
    };
  },
  computed: {
    ...mapGetters(["elements", "language", "apprAchiCountDetails"])
  },
  created() {
    this.getParamsDetail();
    this.getUserInfoAll();
  },
  methods: {
    getParamsDetail() {
      this.listObj = this.apprAchiCountDetails;
    },
    // 添加备注
    addDescFn() {
      let obj = {};
      obj.orderId = this.listObj.orderId;
      obj.type = '1';
      getApprovalRemark(obj)
      .then(res => {
        if (res.status === 200) {
          this.dialogDescForm = true;
          this.descForm.remark = res.data;
        }
      })
    },
    // 用户全部信息
    getUserInfoAll() {
      this.userAllInfoPage.orderId = this.listObj.orderId;
      this.userAllInfoPage.channel = this.listObj.channel;
      userAllOrderByChannel(this.userAllInfoPage).then(response => {
        if (response.status === 200) {
          response.data.rows.forEach(item => {
            let re = /(?=(?!\b)(\d{3})+$)/g;
            let str = String(item.approvedAmt);
            item.approvedAmt = str.replace(re, ",");
          });
          this.userAllInfoDetail = response.data.rows;
          this.userInfoTotal = Number(response.data.total);
        }
      });
    },
    handleSizeChangeUserInfo(val) {
      this.userAllInfoPage.limit = val;
      this.getUserInfoAll();
    },
    handleCurrentChangeUserInfo(val) {
      this.userAllInfoPage.page = val;
      this.getUserInfoAll();
    }
  }
};
</script>

<style scoped lang='scss'>
.title {
  line-height: 22px;
  font-size: 16px;
  display: flex;
  align-items: center;
  font-weight: bold;
  font-weight: bold;
}
.title:before {
  display: block;
  content: "";
  width: 3px;
  height: 16px;
  background-color: #309afe;
}
.title:before {
  margin-right: 8px;
}
::before {
  box-sizing: inherit;
  -webkit-tap-highlight-color: transparent;
}
.menu-title {
  width: 100%;
  box-sizing: border-box;
  background: #ffffff;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  .searchItem {
    display: flex;
    align-items: center;
    padding: 10px 0;
    span {
      display: inline-block;
      width: 100px;
      text-align: right;
      font-size: 12px;
      color: #5f5f61;
      padding-right: 5px;
    }
    div:nth-child(2) {
      width: 150px;
    }
  }
  .searchItem-date {
    display: flex;
    align-items: center;
    padding: 10px 0;
    b {
      margin: 0 10px;
      font-weight: normal;
      font-size: 12px;
      color: #5f5f61;
    }
    div {
      width: 150px;
    }
  }
}
.menu-title-btn {
  padding: 10px 0;
  box-sizing: border-box;
  button {
    padding: 0 20px;
    height: 28px;
    background: #20a0ff;
    color: #fff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
    margin-left: 10px;
    &:nth-child(1) {
      margin-left: 0;
    }
    &:nth-child(2) {
      background: #ebf5ff;
      color: #20a0ff;
      border: 1px solid #abd5ff;
    }
  }
}
.menu-list {
  padding: 20px 0;
  box-sizing: border-box;
  .left {
    button {
      padding: 0 20px;
      height: 28px;
      background: #20a0ff;
      color: #fff;
      outline: none;
      border-width: 0;
      border-radius: 4px;
      font-size: 12px;
      margin-left: 10px;
      &:nth-child(1) {
        margin-left: 0;
      }
    }
    button[disabled] {
      padding: 0 20px;
      height: 28px;
      background: #c1e0ff;
      color: #fafbff;
      outline: none;
      border-width: 0;
      border-radius: 4px;
      font-size: 12px;
    }
  }
}
.el-date-editor.el-input {
  width: 193px;
}
.menu-list {
  width: 100%;
  display: flex;
  justify-content: space-between;
}
.statistics {
  div {
    margin-right: 40px;
    font-size: 16px;
  }
}
.head-title2 {
  display: flex;
  justify-content: space-between;
}
</style>